<template>
    <view class="padding">
        <view class="grid col-3 grid-square">
            <view class="bg-img" v-for="(item,index) in images" :key="index" @click="clickImage(index)">
                <image :src="item" mode="aspectFill">
                </image>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    props: {
        images: {
            type: Array,
            default: () => { return []; }
        }
    },
    data() {
        return {

        };
    },
    methods: {
        clickImage: function(index) {
            console.log('click', index);
            let imageUrl = this.images.map((image) => {
                return 'https:' + image;  //图片需要https开头才能预览
            });
            uni.previewImage({
                current: index,
                urls: imageUrl,
                longPressActions: {
                    itemList: ['发送给朋友', '保存图片', '收藏'],
                    success: function(data) {
                        console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) +
                                '张图片');
                    },
                    fail: function(err) {
                        console.log(err.errMsg);
                    }
                }
            });
        }
    }
};
</script>

<style>
</style>
